package com.springapp.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.springapp.model.ItemInOrder;
import com.springapp.model.Order;
import com.springapp.repository.ItemInOrderRepository;

/*
 * 
 * @uthor Sim4ik
 * 
 */

@Service
public class ItemInOrderServiceImpl {
	
	 	@Autowired
	    ItemInOrderRepository itemInOrderRepository;

	    public ItemInOrder getById(Integer id) {
	        return itemInOrderRepository.findOne(id);
	    }

	    public List<ItemInOrder> getAll() {
	        return (ArrayList<ItemInOrder>) itemInOrderRepository.findAll();
	    }

	    public void create(ItemInOrder itemInOrder) {
	    	itemInOrderRepository.save(itemInOrder);
	    }

	    public ItemInOrder update(ItemInOrder itemInOrder){
	        return itemInOrderRepository.save(itemInOrder);
	    }

	    public void delete(Integer id) {
	    	itemInOrderRepository.delete(id);
	    }
	    
	    public void deleteByOrder(Integer orderId){
	    	itemInOrderRepository.deleteItemInOrderByOrderId(orderId);
	    }
}
